import 'package:flutter/material.dart';
import 'package:flutter_app_getx/page/view/home_view.dart';
import 'package:flutter_app_getx/page/view/view2.dart';

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _currentIndex = 0;
  List _pageList = [
    HomeView(),
    View2(),

  ];
  final items = [
    BottomNavigationBarItem(
        icon: ImageIcon(AssetImage("images/time.png")), label: "出勤記錄"),
    BottomNavigationBarItem(
        icon: ImageIcon(AssetImage('images/roster.png')), label: "更表"),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: <Widget>[
          Offstage(
            offstage: _currentIndex !=0,
            child: _pageList[0],
          ),Offstage(
            offstage: _currentIndex !=1,
            child: _pageList[1],
          ),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: this._currentIndex,
        //配置对应的索引值选中
        onTap: (int index) {
          setState(() {
            //改变状态
            this._currentIndex = index;
          });
        },
        fixedColor: Color(0xff00A89D),
        //选中的颜色
        unselectedItemColor: Color(0xff888DA6),
        unselectedFontSize: 15,
        selectedFontSize: 15,
        type: BottomNavigationBarType.fixed,
        //配置底部tabs可以有多个按钮
        items: items,
      ),
    );
  }
}
